FROM php:7.2-fpm

# ===== 关键：修复 Debian Buster 仓库源（归档仓库）=====
# 1. 备份原 sources.list（可选）
RUN cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 2. 替换为归档仓库（Debian 对停止支持版本的存储）
RUN echo "deb http://archive.debian.org/debian buster main contrib non-free" > /etc/apt/sources.list && \
    echo "deb http://archive.debian.org/debian-security buster/updates main contrib non-free" >> /etc/apt/sources.list && \
    # 3. 允许使用过期仓库（归档仓库签名已过期，必需）
    echo "Acquire::Check-Valid-Until \"false\";" > /etc/apt/apt.conf.d/99no-check-valid-until

# ===== 拷贝扩展安装脚本并执行 =====
COPY extensions.sh /usr/local/bin/extensions.sh
RUN chmod +x /usr/local/bin/extensions.sh && \
    # 4. 安装扩展前先更新仓库（使用归档仓库）
    apt-get update && \
    # 5. 执行扩展安装脚本
    /usr/local/bin/extensions.sh && \
    # 6. 后续配置（日志目录、Composer 等）
    mkdir -p /var/log/php && \
    chown -R www-data:www-data /var/log/php && \
    chmod -R 755 /var/log/php && \
    curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer && \
    chmod +x /usr/bin/composer && \
    composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

# 拷贝 PHP 配置
COPY php.ini /usr/local/etc/php/php.ini

WORKDIR /var/www/html